﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;
using WinFormsApp1.MVVM.ViewModel;

namespace WinFormsApp1.MVVM
{
	public partial class MainForm : Form
	{

		private PersonViewModel _viewModel;

		public MainForm()
		{
			InitializeComponent();

			_viewModel = new PersonViewModel();
			BindControls();
		}
		private void BindControls()
		{
			txtName.DataBindings.Add("Text", _viewModel, nameof(_viewModel.Name), true, DataSourceUpdateMode.OnPropertyChanged);
			txtAge.DataBindings.Add("Text", _viewModel, nameof(_viewModel.Age), true, DataSourceUpdateMode.OnPropertyChanged);
			lblResult.DataBindings.Add("Text", _viewModel, nameof(_viewModel.Message), true, DataSourceUpdateMode.OnPropertyChanged);
			btnSubmit.Click += (s, e) => _viewModel.SubmitCommand.Execute(null);
		}
		private void MainForm_Load(object sender, EventArgs e)
		{

		}

		private void button1_Click(object sender, EventArgs e)
		{

		}
	}
}
